package com.pro.controller;

import com.pro.pojo.JsonData;
import com.pro.pojo.SyCourseRecord;
import com.pro.service.JsAuditLogService;
import com.pro.service.SyCourseRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping(value = "/SyCourseRecord")
public class SyCourseRecordController {
    @Autowired
    private SyCourseRecordService syCourseRecordService;
    @Autowired
    private JsAuditLogService jsAuditLogService;

    //分别获取 待审核、已审核、审核通过的商品数量
    @RequestMapping(value = "/getProductsCount")
    @ResponseBody
    public JsonData getProductsCount(String result){
        Integer productsCount = syCourseRecordService.getProductsCount(result);
        return productsCount != null ? JsonData.buildSuccess(productsCount) : JsonData.buildError("服务器出错了");
    }
    //修改商品审核状态
    @RequestMapping(value = "/updateProductRecordResult")
    @ResponseBody
    public JsonData updateProductRecordResult(SyCourseRecord syCourseRecord){
        System.out.println(syCourseRecord);
        boolean updateProductRecordResult = syCourseRecordService.updateProductRecordResult(syCourseRecord);
        boolean addAuditLog = addAuditLog(syCourseRecord);
        return updateProductRecordResult && addAuditLog ? JsonData.buildSuccess(updateProductRecordResult) : JsonData.buildError("服务器出错了");
    }
    //修改商品审核状态
    @RequestMapping(value = "/updatedetails")
    @ResponseBody
    public JsonData updatedetails(SyCourseRecord syCourseRecord){
        boolean updateProductRecordResult = syCourseRecordService.updateProductRecordResult(syCourseRecord);
        if (updateProductRecordResult){
            boolean updatedetails = syCourseRecordService.updatedetails(syCourseRecord);
            return updatedetails? JsonData.buildSuccess(updatedetails) : JsonData.buildError("服务器出错了");
        }else{
            return updateProductRecordResult? JsonData.buildSuccess(updateProductRecordResult) : JsonData.buildError("服务器出错了");
        }

    }

    //添加审核日志
    private boolean addAuditLog(SyCourseRecord syCourseRecord){
        return jsAuditLogService.addAuditLog(syCourseRecord);
    }



    @RequestMapping(value = "/addProductRecord")
    @ResponseBody
    public JsonData addProductRecord(SyCourseRecord examine){
        boolean b = syCourseRecordService.addProductRecord(examine);
        return b ? JsonData.buildSuccess(b) : JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/addJsCourseRecord")
    @ResponseBody
    public JsonData addJsCourseRecord(SyCourseRecord param){
        boolean b = syCourseRecordService.addJsCourseRecord(param);
        return b ? JsonData.buildSuccess(b) : JsonData.buildError("服务器出错了");
    }
    //查询待审核商品、课程、微圈
    @RequestMapping(value = "/getToAuditsCount")
    @ResponseBody
    public JsonData getToAuditsCount(SyCourseRecord syCourseRecord){
        Integer toAuditsCount = syCourseRecordService.getToAuditsCount(syCourseRecord);
        return toAuditsCount != null ? JsonData.buildSuccess(toAuditsCount) : JsonData.buildError("服务器出错了");
    }
}
